#include<bits/stdc++.h>
#define ll long long
using namespace std;
int t,n;
int lstr,lstb;
ll ans=0;
ll a[200005];
ll suf[200005];
void dfs(int x,ll sum){
    if(x==n+1){
        ans=max(ans,sum);
        return;
    }
    if(sum+suf[x]<=ans)  return;
    int r=lstr,b=lstb;
    if(lstr!=-1){
        if(a[lstr]==a[x]){
            lstr=x;
            dfs(x+1,sum+a[x]);
        }
        else{
            lstr=x;
            dfs(x+1,sum);
        }
        lstr=r;
    }
    else{
        lstr=x;
        dfs(x+1,sum);
        lstr=r;
    }
    if(lstb!=-1){
        if(a[lstb]==a[x]){
            lstb=x;
            dfs(x+1,sum+a[x]);
        }
        else{
            lstb=x;
            dfs(x+1,sum);
        }
        lstb=b;
    }
    else{
        lstb=x;
        dfs(x+1,sum);
        lstb=b;
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)  scanf("%lld",&a[i]);
        memset(suf,0,sizeof(suf));
        ans=0;
        lstr=-1,lstb=-1;
        for(int i=1;i<=n;i++)  suf[i]=suf[i+1]+a[i];
        dfs(1,0);
        printf("%lld\n",ans);
    }
    return 0;
}

